package com.zcxy.fast.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxy.fast.anotation.Log;
import com.zcxy.fast.bean.PageQuery;
import com.zcxy.fast.bean.Response;
import com.zcxy.fast.bean.TreeNode;
import com.zcxy.fast.entity.SysCategory;
import com.zcxy.fast.vo.SysCategoryVo;
import com.zcxy.fast.service.ISysCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * 分类字典Controller
 *
 * @author zcc
 * @email  860474958@qq.com
 * @date   2020-12-25 17:39:33
 */
@RestController
@RequestMapping("/api/sysCategory")
@Api(tags = "分类字典管理")
@Slf4j
public class SysCategoryController {
    @Autowired
    private ISysCategoryService iSysCategoryService;

    @Log("获取分类字典数据--分页")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(分类字典)分页数据列表", notes = "获取(分类字典)分页数据列表")
    public Response<IPage<SysCategoryVo>> queryPageList(@RequestBody PageQuery<SysCategory> queryVo) {

        return Response.ok(iSysCategoryService.queryPageList(queryVo));
    }

    @Log("获取分类字典数据-列表")
    @PostMapping(value = "/queryList")
    @ApiOperation(value = "获取分类字典数据-列表", notes = "获取分类字典数据-列表")
    public Response<List<SysCategoryVo>> queryList(SysCategory sysCategory) {
        return Response.ok(iSysCategoryService.queryList( sysCategory));
    }


    @Log("添加分类字典数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加分类字典数据", notes = "添加分类字典数据")
    public Response addSysCategory(@RequestBody @Validated @NotNull SysCategory queryVo) {
        iSysCategoryService.addSysCategory(queryVo);
        return Response.ok();
    }


    @Log("修改分类字典数据")
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改分类字典数据", notes = "修改分类字典数据")
    public Response updateSysCategory(@RequestBody @Validated @NotNull SysCategory queryVo) {
        iSysCategoryService.updateSysCategory(queryVo);
        return Response.ok();
    }


    @Log(value = "批量删除分类字典")
    @ApiOperation("批量删除分类字典")
    @PostMapping("/dels")
    public Response deleteByIds(@RequestBody List<String> ids) {
        iSysCategoryService.removeAllSysCategory(ids);
        return Response.ok();
    }


    @Log(value = "根据父id树形结构")
    @ApiOperation("根据父id树形结构")
    @GetMapping("/queryTreeNodeList")
    public Response<List<Map>> queryTreeNodeList(@RequestParam(required = false) String parentId) {

        return Response.ok(iSysCategoryService.queryTreeNodeList(parentId));
    }


    @Log(value = "根据父id树形结构")
    @ApiOperation("根据父id树形结构")
    @GetMapping("/queryAllTreeNodeList")
    public Response<List<TreeNode>> queryAllTreeNodeList() {
        return Response.ok(iSysCategoryService.queryTreeNodeList());
    }


    @Log(value = "根据分类code获取树形结构")
    @ApiOperation("根据分类code获取树形结构")
    @GetMapping("/queryAllTreeNodeListByFistCode")
    public Response<List<TreeNode>> queryAllTreeNodeListByFistCode(String code ) {
        return Response.ok(iSysCategoryService.queryTreeNodeListByFirstCategoryCode(code));
    }
}
